package com.vcredit.creditcat.web.app;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.vcredit.creditcat.api.IAlipayProcessManager;
import com.vcredit.creditcat.dto.emallcredit.AlipayProcessInDto;
import com.vcredit.creditcat.model.Cust;
import com.vcredit.creditcat.vo.AlipayCheckQRCodeVo;
import com.vcredit.creditcat.vo.AlipayQRCodeVo;
import com.vcredit.creditcat.vo.JsonResult;
import com.vcredit.framework.annotation.InterfaceRequest;
import com.vcredit.framework.annotation.Log;

@RestController
@RequestMapping(value = "/alipay")
public class AlipayProcessController extends BaseCreditCatController {

	@Reference(version = "1.0")
	private IAlipayProcessManager alipayProcessManager;

	
	/**
	 * 支付宝登录接口
	 * 用于获取支付宝网页中cookies、用户名、密码等信息
	 * @author zhaoqi01
	 * @param param
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("rawtypes")
	@Log
	@RequestMapping(value = "/login")
	@InterfaceRequest(value = "支付宝信息采集接口")
	public JsonResult getAlipayInfo(@RequestBody AlipayProcessInDto param, HttpServletRequest request)
			throws Exception {
		Cust cust = getCust(request);
		alipayProcessManager.alipayCookieCrawl(param, cust);
		return JsonResult.SuccessResponse(null);
	}
	
	/**
	 * 支付宝二维码获取接口 
	 * @author zhaoqi01
	 * @param param
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@Log
	@RequestMapping(value = "/qrCode")
	public JsonResult<AlipayQRCodeVo> qrCode(@RequestBody AlipayProcessInDto param,HttpServletRequest request)
			throws Exception {
		Cust cust = getCust(request);
		String VerCodeBase64 = alipayProcessManager.getQRCode(param, cust);
		return JsonResult.SuccessResponse(new AlipayQRCodeVo(VerCodeBase64));
	}
	
	/**
	 * 支付宝二维码校验接口 
	 * @author zhaoqi01
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@Log
	@RequestMapping(value = "/checkQrCode")
	public JsonResult<AlipayCheckQRCodeVo> qrCode(HttpServletRequest request)
			throws Exception {
		Cust cust = getCust(request);
		return JsonResult.SuccessResponse(new AlipayCheckQRCodeVo(alipayProcessManager.checkQRCode(cust).trim()));
	}
}
